package com.liwy3.serialize.controller;

import cn.hutool.json.JSONUtil;
import com.liwy3.common.domain.R;
import com.liwy3.serialize.dto.EhrUserDetailReqDTO;
import com.liwy3.serialize.dto.EhrUserDetailRespDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.Cache;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.cache.RedisCache;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Copyright © 元气森林（北京）食品科技集团有限公司. All rights reserved.
 *
 * @Description:
 * @author: Crazy4J
 * @date: 2022年04月07日 11:43
 * @version: V1.0
 */
@RestController
@Slf4j
public class SerializeController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;


    @PostMapping("/s1")
    public R<EhrUserDetailRespDTO> detail(@RequestBody EhrUserDetailReqDTO ehrUserDetailReqDTO) {

        log.info("入参:" + JSONUtil.toJsonStr(ehrUserDetailReqDTO));
        EhrUserDetailRespDTO ehrUserDetailRespDTO = new EhrUserDetailRespDTO();
        ehrUserDetailRespDTO.setUserId("1234").setCategory(1).setCreateTime(new Date()).setStartTime("2022-11-22 12:12:11");
        log.info("出参:" + JSONUtil.toJsonStr(ehrUserDetailRespDTO));

        return R.ok(ehrUserDetailRespDTO);
    }


    @PostMapping("/s2")
    @Cacheable("redisDetail")
    public R<EhrUserDetailRespDTO> redisDetail(@RequestBody EhrUserDetailReqDTO ehrUserDetailReqDTO) {

        log.info("入参2:" + JSONUtil.toJsonStr(ehrUserDetailReqDTO));
        EhrUserDetailRespDTO ehrUserDetailRespDTO = new EhrUserDetailRespDTO();
        ehrUserDetailRespDTO.setUserId("1234").setCategory(1).setCreateTime(new Date()).setStartTime("2022-11-22 12:12:11");
        log.info("出参2:" + JSONUtil.toJsonStr(ehrUserDetailRespDTO));



        return R.ok(ehrUserDetailRespDTO);
    }

}
